package com.voja.workoutrandomizer;

import java.util.ArrayList;

import org.json.JSONObject;

import com.voja.workoutrandomizer.repository.Workout;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class WorkoutsAdapter extends ArrayAdapter<Workout> {

	private ArrayList<Workout> workouts;
	private Context context;
	int     viewId;
	
	public WorkoutsAdapter(Context context, int viewId, ArrayList<Workout> workouts) {
		super(context, viewId, workouts);
		
		this.workouts = workouts;
		this.context  = context;
		this.viewId   = viewId;
	}
	
	@Override
	public Workout getItem(int position) {
		return workouts.get(position);
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = ((Activity)context).getLayoutInflater().inflate(viewId, parent, false);
		}
		
		Workout workout = getItem(position);
		TextView tvTitle = (TextView)convertView.findViewById(R.id.workoutTitle);
		tvTitle.setText(workout.getTitle());
		
		return convertView;
	}
	
}
